﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="d">

    <ControlTemplate x:Key="RibbonControlTemplate"
                     TargetType="{x:Type Fluent:Ribbon}">
        <Grid x:Name="PART_LayoutRoot"
              Width="Auto"
              Height="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Fluent:RibbonTitleBar x:Name="PART_RibbonTitleBar"
                                   Height="25"
                                   Style="{DynamicResource RibbonTitleBarStyle}"
                                   Margin="20,0,113,0"
                                   VerticalAlignment="Top"
                                   IsCollapsed="{TemplateBinding IsCollapsed}">
                <Fluent:RibbonTitleBar.Header>
                    <TextBlock x:Name="PART_Title"
                                Margin="-2,0"
                                VerticalAlignment="Center"
                                d:LayoutOverrides="Width"
                                HorizontalAlignment="Center"
                                Text="{Binding Path=Title,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                Foreground="Black"
                                TextWrapping="NoWrap"
                                TextTrimming="CharacterEllipsis" />
                </Fluent:RibbonTitleBar.Header>
            </Fluent:RibbonTitleBar>

            <Fluent:RibbonTabControl Menu="{TemplateBinding Menu}"
                                     Style="{DynamicResource RibbonTabControlStyle}"
                                     x:Name="PART_RibbonTabControl"
                                     Margin="0,25,0,0"
                                     Focusable="False"
                                     ContextMenu="{Binding ContextMenu, ElementName=PART_LayoutRoot}" />
            <!--<ContentPresenter x:Name="button" Margin="2,26,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
                          ContentSource="Menu"/>-->
            <Border x:Name="border"
                    Margin="0,-2,0,0"
                    BorderBrush="{DynamicResource QuickAccessToolBarOutterBorderBrush}"
                    BorderThickness="0,1"
                    Grid.Row="1"
                    Height="26">
                <Border BorderBrush="{DynamicResource QuickAccessToolBarInnerBorderBrush}"
                        BorderThickness="0,1"
                        Background="{DynamicResource QuickAccessToolBarInnerBackgroundBrush}">
                    <ContentControl x:Name="contentControl"
                                    HorizontalAlignment="Left">
                        <Fluent:QuickAccessToolBar x:Name="PART_QuickAccessToolBar"
                                                   Style="{DynamicResource QuickAccessToolbarStyle}"
                                                   ShowAboveRibbon="{Binding ShowQuickAccessToolBarAboveRibbon, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                   HorizontalAlignment="Left"
                                                   Focusable="False" />
                    </ContentControl>
                </Border>
            </Border>           
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsQuickAccessToolBarVisible"
                     Value="False">
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_QuickAccessToolBar"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsCollapsed"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="PART_RibbonTabControl"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />
                <!-- Setting height to the exact same value as GlassBorderThickness -->
                <Setter Property="Height"
                        TargetName="PART_RibbonTitleBar"
                        Value="{Binding GlassBorderThickness.Top, RelativeSource={RelativeSource AncestorType={x:Type Fluent:RibbonWindow}}, FallbackValue=30}" />                
            </Trigger>
            <Trigger Property="ShowQuickAccessToolBarAboveRibbon"
                     Value="True">
                <Setter Property="Content"
                        TargetName="contentControl"
                        Value="{x:Null}" />
                <Setter Property="QuickAccessToolBar"
                        TargetName="PART_RibbonTitleBar"
                        Value="{Binding ElementName=PART_QuickAccessToolBar, Mode=OneWay}" />
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Collapsed" />
                <Setter Property="Margin"
                        TargetName="PART_QuickAccessToolBar"
                        Value="0,2,0,0" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="RibbonStyle"
           TargetType="{x:Type Fluent:Ribbon}">
        <Setter Property="Foreground"
                Value="{DynamicResource DefaultFontBrush}" />
        <Setter Property="FontFamily"
                Value="{DynamicResource DefaultFontFamily}" />
        <Setter Property="FontSize"
                Value="{DynamicResource DefaultFontSize}" />
        <Setter Property="Template"
                Value="{StaticResource RibbonControlTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="FocusManager.IsFocusScope"
                Value="False" />
        <Setter Property="VerticalAlignment"
                Value="Top" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="Fluent:FrameworkHelper.UseLayoutRounding"
                Value="True" />
        <Setter Property="Margin"
                Value="0,-30,0,0" />
    </Style>
</ResourceDictionary>
